<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>显示隐藏文本框内容</title>
   
</head>
<body>
    搜索:<input type="text" value="胡歌">
    <script>
        var txt=document.querySelector('input')
        txt.onfocus=function(){
            if(this.value){
                this.value='';
            }
            txt.style.color='black'
            // console.log('djkd');
        }
        txt.onblur=function(){
            if(this.value==''){
                this.value='胡歌'
            }
            txt.style.color='silver'
            // console.log('hhh');
        }
    </script>
</body>
</html>